package com.itheima.reggie.mappers;

import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.dto.DishDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishMapper {
    @Select("SELECT COUNT(*) FROM dish WHERE category_id=#{id}")
    Integer selectByCategoryId(Long id);

    @Insert("insert into dish values(null,#{name},#{categoryId},#{price},#{code}," +
                    "#{image},#{description},#{status},#{sort},#{createTime}," +
                    "#{updateTime},#{createUser},#{updateUser},0)")
    //插入之后主键封装给dishDto
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void save(DishDto dishDto);

    List<Dish> findByName(String name);

    @Select("select * from dish where id=#{id}")
    Dish findById(Long id);

    void update(DishDto dishDto);

    // @Select("select * from dish where category_id=#{categoryId} and status=#{status}")
    List<Dish> findByCategoryId(Long categoryId,Integer status);

    Integer findCountById(Long[] ids);

    void delete(Long[] ids);

    void updateStatus(List<Long> ids, int status);
}
